from selenium.webdriver.common.by import By

from base.AppBase.appbase import AppBasePage, AppBaseHandle
from utils import app_swipe_find


class IndexPage(AppBasePage):
    def __init__(self):
        super().__init__()
        self.scroll_button = By.ID, "com.netease.newsreader.activity:id/bn9"
        self.channel = By.XPATH, "//com.netease.newsreader.activity:id/bn9/*[contains(@text,'{}')]"
        # self.scroll_element = get_element(driver, scroll_button)

    def find_scroll_btn(self):
        return self.get_element(self.scroll_button)


class IndexHandle(AppBaseHandle):
    def __init__(self):
        self.index_page = IndexPage()

    def click_channel(self, channel):
        xpath = self.index_page.channel[0], self.index_page.channel[1].format(channel)
        app_swipe_find(self.index_page.driver, self.index_page.find_scroll_btn(), xpath)


class IndexProxy:
    def __init__(self):
        self.index_handle = IndexHandle()

    def find_channel(self, channel):
        self.index_handle.click_channel(channel)
